<template>
  <div>
    <h1>当前求和为{{ sum }}</h1>
    <select v-model.number="number">
      <!-- 或者:value -->
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="addNumber">+</button>
    <button @click="reduceNumber">-</button>
    <button @click="oddAddNumber">当前的求和值为奇数再加</button>
    <button @click="delayAddNumber">等500ms后再加</button>
  </div>
</template>

<script>
export default {
  name: "Count",
  data() {
    return {
      number: 1, //默认选中1
      sum: 0, //当前的和
    };
  },
  methods: {
    addNumber() {
      this.sum += this.number;
    },
    reduceNumber() {
      this.sum -= this.number;
    },
    oddAddNumber(e) {
      if (this.sum % 2 === 0) {
      } else {
        this.sum += this.number;
      }
    },
    delayAddNumber() {
      setTimeout(() => {
        this.sum += this.number;
      }, 500);
    },
  },
};
</script>

<style scoped>
button {
  margin: 0 5px 0 5px;
}
</style>